package cn.gameo2o.controller.xmgl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.gameo2o.pojo.O2o_game;
import cn.gameo2o.service.xmgl.XiangMuGuanLiService;
import cn.gameo2o.util.PageParam;


/**
 * 活动管理controller
 * @author 孙祺然
 */

@Controller
@RequestMapping("/xmgl")
public class XiangMuGuanLiController{
	
	@Resource()
    private XiangMuGuanLiService xmService;

    public XiangMuGuanLiService getxmService() {
        return xmService;
    }

    public void setxmService(XiangMuGuanLiService xmService) {
        this.xmService = xmService;
    }
    @RequestMapping("/findAll")
    public PageParam findAll(@RequestParam(required = false) String gameId,@RequestParam(required = false) String gameName,@RequestParam(required = false) String gameTime,@RequestParam(required=false) int gameScore,@RequestParam(required=false) String gameRules,@RequestParam() Integer limit,@RequestParam() Integer offset){
          Map param=new HashMap();
          if(gameId!=null) {
              param.put("gameId", gameId);
          }
          if(gameName!=null){
              param.put("gameName",gameName);
          }
          if(gameTime!=null){
              param.put("gameTime",gameTime);
          }
          if(gameScore!=0){
        	  param.put("gameScore", gameScore);
          }
          if(gameRules!=null){
        	  param.put("gameRules", gameRules);
          }

          PageParam page=new PageParam();
          page.setPageSize(limit);
          page.setFirst(offset);
          xmService.find(param,page);
          return page;
    }
    @RequestMapping("/save")
    public String save(@ModelAttribute O2o_game game){
        xmService.save(game);
        return "添加成功！";
    }
    @RequestMapping("/del")
    public String delete(@RequestParam(value = "xmid",required = false) String xmid){
        xmService.delete(Integer.parseInt(xmid));
        return "index";
    }

    @RequestMapping("/findById")
    public O2o_game findById(@RequestParam(value="xmid",required=false) String xmid ){
    	O2o_game game = xmService.findById(Integer.parseInt(xmid));
        return game;
    }

    @RequestMapping("/update")
    public String update(@ModelAttribute O2o_game game){
        xmService.update(game);
        return "更新成功！";
    }

	
	
	
}